<?php
    //tool buttons
    $tool_buttons = array();
    if ($this->data['system_table_id'] != null)
    {
    	$tool_buttons = array
    	(
    		'list_button' => array
    		(
    			'image'=>'btnListLarge.gif', 
    			'text'=>LANG_LIST, 
    			'url'=>'/'.$this->name.'/edit/'.$this->data['role_id']
    		)
    	);	
    	
    }	
	$tool_buttons = $tool_buttons + array
	(
	    'access_list_button' => array
		(
			'image'=>'btnListLarge.gif', 
			'text'=>LANG_ACCESS,
			'url'=>'/system_access/edit/'.$this->data['role_id']
		)
	);

    //header
    $this->helpers->htmlx->MenuText1(LANG_SYSTEM_PERMISSIONS_COLUMNS.': '.LANG_EDIT.' '.LANG_FOR.' "'.$this->data['role']['name'].'"', "edit.gif");
    
    //toolbar
    $this->helpers->toolbars->Toolbar($tool_buttons);
    
    //table name
    $table_name = "";
    
    if (!empty($this->data['permissions']))
    {    
    	//form
        XHTML::Form('/'.$this->name.'/edit/'.$this->data['role_id']);  
          
        echo "<table class='grid' cellspacing = '1'>";
            
            //header row
            echo "<tr class = 'ui-widget-header'>";
            	$this->helpers->htmlx->td(ucfirst(LANG_TABLE_COLUMN_NAME), ' class = "gridHeader" style = "padding: 3px; " ');
                $this->helpers->htmlx->td(ucfirst(LANG_VIEW), ' class = "gridHeader" style = "padding: 3px; " align = "center"');
            	$this->helpers->htmlx->td(ucfirst(LANG_EDIT), ' class = "gridHeader" style = "padding: 3px; " align = "center"');
            	$this->helpers->htmlx->hidden('system_table_id', $this->data['system_table_id']);	
            echo "</tr>";
        
            //columns
        	$i = 1;
        	foreach ($this->data['permissions'] as $permission)
        	{
                $cellStyle = 'gridCell';
        		
        		echo "<tr>";
        		
        		    //if new table
            		if ($table_name != $permission['system_table_name'])
            		{
            		    echo "<tr class = ''> <td colspan = '3' align = 'left' class = '$cellStyle' style = 'font-weight: 900; height: 20px; '>";
            			    echo Language::Get(str_replace('LANG_', '', $permission['language_constant']), 'CAPITALIZE'); 
            			echo "</td> </tr>";
            		}
            		
            		//column name (translated)
    	    		echo "<td class = '$cellStyle'>";
    	    		    echo Language::Get(str_replace('LANG_', '', $permission['system_table_column_constant']), 'LOWERCASE').' ';
    	    		echo "</td>"; 	
    	    		
    	    		//permission for view
    	    		echo "<td class='$cellStyle' align = 'center'>";
    	    			XHTML::InputCheckbox('permission['.$permission['id'].'][view]', 1, $permission['view'], 'id = "view'.$permission['id'].'" onclick = "document.getElementById(\'edit'.$permission['id'].'\').checked = false"');   		
    	    		echo "</td>";  
    	    		
    	    		//permission for edit
    	    		echo "<td class='$cellStyle' align = 'center'>";
    	    			XHTML::InputCheckbox('permission['.$permission['id'].'][edit]', 1, $permission['edit'], 'id = "edit'.$permission['id'].'" onclick = "document.getElementById(\'view'.$permission['id'].'\').checked = true"');   		
    	    		echo "</td>";  
    	    		
    	    		XHTML::InputHidden('permission['.$permission['id'].'][id]', $permission['id']); 
    	    		 
                echo "</tr>";
        		$i++;
        		$table_name = $permission['system_table_name'];
        	}
        	
        echo "</table>";
        $this->helpers->htmlx->submitTable('submit','system_access/edit/'.$this->data[role_id]);
        echo "</form>";
    }
    else
    {
        echo "<br />".ucfirst(Language::Get('No columns'))."<br /><br />";
    }
?>